package labox.innovation.gameserver.network.serverpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;
import labox.innovation.gameserver.model.L2ItemInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

/**
 * �·��ֿ��б�
 * 0x42 WarehouseWithdrawalList  dh (h dddhh dhhh d)
 *
 * @version $Revision: 1.3.2.1.2.5 $ $Date: 2005/03/29 23:15:10 $
 */
public final class WareHouseWithdrawalList extends L2GameServerPacket {
	public static final int PRIVATE = 1;

	public static final int CLAN = 4;

	public static final int CASTLE = 3; //not sure

	public static final int FREIGHT = 1;

	private static final Logger _log = LoggerFactory.getLogger(WareHouseWithdrawalList.class.getName());

	private static final String _S__54_WAREHOUSEWITHDRAWALLIST = "[S] 42 WareHouseWithdrawalList";

	private FuzePcInstance _activeChar;

	private long _playerAdena;

	private L2ItemInstance[] _items;

	private int _whType;

	public WareHouseWithdrawalList(FuzePcInstance player, int type) {
		_activeChar = player;
		_whType = type;

		_playerAdena = _activeChar.getMoneySilver();
		if (_activeChar.getActiveWarehouse() == null) { //-- �ֿ�û��Ʒ��ֱ���˳�
			// Something went wrong!
			_log.warn("error while sending withdraw request to: " + _activeChar.getName(), Config.SERVER_ID, "�·��ֿ��б�");
			return;
		} else
			_items = _activeChar.getActiveWarehouse().getItems();

		if (_log.isDebugEnabled())
			for (L2ItemInstance item : _items)
				_log.debug("item:" + item.getItem().getName() + " type1:" + item.getItem().getType1() + " type2:" + item.getItem().getType2(), Config.SERVER_ID, "�·��ֿ��б�");
	}

	@Override
	protected final void writeImpl() {
		writeByte(0x42);
		/* 0x01-Private Warehouse
		* 0x02-Clan Warehouse
		* 0x03-Castle Warehouse
		* 0x04-Warehouse */
		writeInt(_whType);
		writeLong(_playerAdena);
		writeInt(_items.length);

		for (L2ItemInstance item : _items) {
			writeInt(item.getItem().getType1());
			writeLong(item.getObjectId());
			writeInt(item.getItemId());
			writeInt(item.getCount());
			writeInt(item.getItem().getType2());
			writeInt(item.getCustomType1());
			writeInt(item.getItem().getBodyPart());
			writeInt(item.getEnchantLevel());
			writeInt(item.getCustomType2());
			writeInt(item.getMana());
			writeInt(item.isTimeLimitedItem() ? (int) (item.getRemainingTime() / 1000) : -1);
		}
	}

	/* (non-Javadoc)
	 * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _S__54_WAREHOUSEWITHDRAWALLIST;
	}
}
